package main

import (
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
	"log"
	"math/rand"
)

const (
	DSN = "root:123456@(127.0.0.1:3306)/test_ascii?charset=utf8mb4&parseTime=True&loc=Local"
)

func main() {
	varLen()
}

func initDb() *gorm.DB {
	db, err := gorm.Open(mysql.Open(DSN), &gorm.Config{})
	if err != nil {
		log.Fatalf("db connect error: %s\n", err.Error())
	}
	return db
}

func varLen() {
	db := initDb()
	db.Exec("insert into t_user(id, name) values(?, ?)", rand.Intn(1000), "xE6")

}
